package jj.controller;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;

import javax.xml.xpath.XPathExpressionException;

import jj.common.Constant;
import jj.connector.AirConnector;
import jj.vo.CityFlightsVo;
import jj.vo.Flight;

import org.springframework.data.document.mongodb.config.MongoParser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.google.gson.Gson;

@Controller
public class BaseController {
	
	@RequestMapping(value = "/index")
	public ModelAndView index(){
		ModelAndView mav = new ModelAndView("index");
		mav.addObject("data", "dataString");
		return mav; 
	}
	
	@RequestMapping("/list/aa")
	public @ResponseBody String getList() throws MalformedURLException, XPathExpressionException, IOException{
		AirConnector conn = new AirConnector();
		List<Flight> depart = conn.getDocumentByParam(Constant.FlightLandingType.DEPARTURE, "20110713", "RKPC" );
		
		CityFlightsVo cityInfo = new CityFlightsVo();
		cityInfo.setArrivalInfo(depart);
		cityInfo.setDepartInfo(depart);
		cityInfo.setCity(Constant.buildCityCode().get("RKPC"));
		cityInfo.setDate("20110713");
		Gson gson = new Gson();
		return gson.toJson(cityInfo);
	}
}
// http://lyb1495.tistory.com/77

//http://blog.naver.com/PostView.nhn?blogId=sleep_later&logNo=40131385913